<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script src="${pageContext.request.contextPath}/js/jquery-3.3.1.js"></script>
<script type="text/javascript">

    function checkForm(){
        var name=document.getElementById("name").value;
        var sex=document.getElementById("sex").value;
        var phone=document.getElementById("phone").value;
        var build = document.getElementsByName("dormBuildId");


        var checks = new Array();
        for(var i = 0; i<build.length;i++){
            if(build[i].checked){
                checks.push(build[i].value);
            }
        }

        if(name==""||sex==""||phone=="" || checks.length < 1 ){
            document.getElementById("error").innerHTML="信息填写不完整！";
            return false;
        }
        if(!/^1[2345678]\d{9}$/.test(phone)){
            document.getElementById("error").innerHTML="手机号码格式错误！";
            return false;
        }
        return true;
    }

    $(document).ready(function(){
        $("#dormManager").addClass("active");
    });
</script>

<script>
    $(function () {
        $.post("/dormBuild/findBuild",{},function (data) {
            var lis = "";
            for(var i=0;i<data.length;i++){
                lis += '<input name="dormBuildId" value="'+data[i].id+'"  style="heigth:14px;vertical-align:top"  type="checkbox" >'+data[i].name+'  &nbsp;';
            }
            $("#build").html(lis);
        })

    });
</script>
<div class="data_list">
    <div class="data_list_title">
        添加员工
    </div>
    <form action="${pageContext.request.contextPath}/dormManager/addManager" method="post" onsubmit="return checkForm()">
        <div class="data_form" >
            <div align="center">
                <font id="error" color="red"></font>
            </div>
            <table align="center">
                <tr>
                    <td><font color="red">*</font>姓名：</td>
                    <td><input type="text" id="name"  name="name" value=""  style="margin-top:5px;height:30px;" /></td>
                </tr>
                <tr>
                    <td><font color="red">*</font>性别：</td>
                    <td>
                        <select id="sex" name="sex" style="width: 90px;">
                            <option value="男">男</option>
                            <option value="女">女</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td><font color="red">*</font>联系电话：</td>
                    <td><input type="text" id="phone"  name="phone" value=""  style="margin-top:5px;height:30px;" /></td>
                </tr>
                <tr>
                    <td><font color="red">*</font>管理楼栋：</td>
                    <td id="build">
                    </td>
                </tr>
            </table>
            <div>--</div>
            <div align="center">
                <input type="submit" class="btn btn-primary" value="确认"/>
                &nbsp;<button class="btn btn-primary" type="button" onclick="javascript:history.back()">返回</button>
            </div>

        </div>
    </form>
</div>
